package com.cn.jm.util;

import java.io.IOException;

/**
 * @author
 * @description 系统时间
 * @date 2020/3/13
 */
public class SystemDateUtil {
    public static String FORMAT_DAY = "yyyy-MM-dd";
    public static String FORMAT_SECOND = "HH:mm:ss";

    public static String setDatetime(String date, String time) {
        String osName = System.getProperty("os.name");
        String dateTimeMessage = date + " " + time;
        try {
            if (osName.matches("^(?i)Windows.*$")) { // Window 系统
                String cmd;

                cmd = " cmd /c date " + date; // 格式：yyyy-MM-dd
                Runtime.getRuntime().exec(cmd);

                cmd = " cmd /c time " + time; // 格式 HH:mm:ss
                Runtime.getRuntime().exec(cmd);
            } else if (osName.matches("^(?i)Linux.*$")) {// Linux 系统
                String command = "date -s " + "\"" + date + " " + time + "\"";// 格式：yyyy-MM-dd HH:mm:ss
                Runtime.getRuntime().exec(command);
            } else {

            }
        } catch (IOException e) {
            return e.getMessage();
        }
        return dateTimeMessage;
    }
}
